package cc.SSM.exceptions;

/**
 * Created by rongmc on 16/3/23.
 * xxx+xx+xxx (错误类型+业务类型+错误码)
 * 例如:500+00+001表示:
 * 500服务器端异常+00系统级错误+001错误类型
 *
 */
public enum SystemExceptionEnum {
    INTERNAL_ERROR(Long.valueOf(50000001), "系统内部异常"),
    APP_ERROR(Long.valueOf(50000002), "未授权应用"),
    SIGN_ERROR(Long.valueOf(50000003), "签名错误"),
    ILLEGAL_PARAM(Long.valueOf(50000004), "请求参数不合法"),
    NO_PRIVILEGE(Long.valueOf(50000005), "无权限访问接口"),
    NO_LOGIN(Long.valueOf(50000006), "未登录"),
    ONLY_HTTPS(Long.valueOf(50000007), "只支持HTTPS访问"),
    REPEAT_REQUEST(Long.valueOf(50000008), "重复操作");


    private Long code;
    private String description;

    private SystemExceptionEnum(Long code, String description) {
        this.code = code;
        this.description = description;
    }

    public static SystemExceptionEnum get(Long code) {
        if(code == null) {
            return null;
        } else {
            SystemExceptionEnum[] arr$ = values();
            int len$ = arr$.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                SystemExceptionEnum appResultCodeEnum = arr$[i$];
                if(appResultCodeEnum.getCode().equals(code)) {
                    return appResultCodeEnum;
                }
            }

            return null;
        }
    }

    public static boolean is(SystemExceptionEnum appResultCodeEnum, Long code) {
        return appResultCodeEnum != null && code != null?appResultCodeEnum.getCode().equals(code):false;
    }

    public Long getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }
}
